<template>
    <div class="show_diary">
      <router-link to="/Diary/Center" class="glyphicon glyphicon-menu-left">返回</router-link>
      <input type="text" placeholder="搜索日记" v-model="search">
      <div v-for="diary in filterDiarys" :key="diary.id" class="single_diary">
        <router-link class="turn" :to="'/Diary/showDiary/' + diary.id">
          <h2>{{diary.title}}</h2>
          <div class="dtype">日记分类:{{diary.type}}</div>
          <div class="time">{{diary.value2}}</div>
          <article>
            {{diary.body | snippet}}
          </article>
        </router-link>
      </div>
    </div>
</template>

<script>
export default {
  name: 'ShowDiary',
  data () {
    return {
      diarys: [],
      search: ''
    }
  },
  created () {
    this.$http.get('http://localhost:3000/diarys/')
      .then(function (data) {
        this.diarys = data.body.slice(0, 10)
        console.log(this.diarys)
      })
  },
  computed: {
    filterDiarys: function () {
      return this.diarys.filter((diary) => {
        return diary.title.match(this.search)
      })
    }
  }
}
</script>

<style scoped>
  .show_diary{
    max-width: 800px;
    margin: 0 auto;
    background: #f4f4f4;
  }

  .single_diary{
    padding: 50px 20px;
    margin: 10px 0;
    box-sizing: border-box;
    background: white;
  }

  #show_diary a{
    color: #444;
    text-decoration: none;
  }

  input[type="text"]{
    margin-top: 10px;
    font-size: 16px;
    padding: 8px;
    padding-left: 20px;
    width: 100%;
    box-sizing: border-box;
    border-radius: 5px;
    background-image: url('../../../assets/icons/搜索.png');
    background-repeat: no-repeat;
    background-position: 95% 50%;
    background-size: 24px 24px;
  }
  h1,h2{
    font-size: 18px;
    text-transform: uppercase;
    text-align: center;
    padding: 10px 0;
    font-weight: bolder;
  }
  .turn{
    color: #66cdaa;
  }
  .turn article{
    font-size: 16px;
    color: black;
  }
  .dtype{
    font-size: 15px;
  }
  .time{
    font-size: 15px;
    padding-left: 70%;
    padding-bottom: 10px;
    color: #428eda;
  }
  .glyphicon{
    margin-top: 7px;
    padding-left: 10px;
    color: mediumaquamarine;
    font-size: 16px;
  }
</style>
